﻿using System.Diagnostics;

using HibernatingRhinos.Profiler.Appender.NHibernate;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using NHibernate;

using ZQNB.Common;
using ZQNB.Common.Encrypt;
using ZQNB.Common.NHExtensions;
using ZQNB.Entity.Accounts;

namespace ZQNB.BaseLib.Users
{
    //对于带有 AssemblyInitialize 属性标记的方法，仅当该方法属于带有 TestClass 属性标记的类的成员时，测试引擎才会运行它
    [TestClass]
    public class SchemaTest
    {
        private static bool _inited = false;
        [AssemblyInitialize]
        public static void SetupTestEnvForEachClass(TestContext context)
        {
            Debug.WriteLine("Assembly Init => ");
            if (_inited)
            {
                return;
            }
            //RbacNinjectLocator.Instance.SetupAutoMapper();
            //生成数据库结构
            SqlUtHelper.Instance = new MyUtHelper();
            //SqlUtHelper.Instance.ReCreateDbIfExist(".", "NbV3DbTest", "sa", "zqnb_123");
            SqlUtHelper.Instance.CreateDbIfNotExist(".", "NbV3DbTest", "sa", "zqnb_123");
            SqlUtHelper.Instance.SetUpNHibernate(true, typeof(AccountMap));

            //准备测试数据
            SqlUtHelper.Instance.InitData();
            _inited = true;

            NHibernateProfiler.Initialize();
        }

        [AssemblyCleanup]
        public static void AssemblyCleanup()
        {
            Debug.WriteLine("Assembly Cleanup => ");
        }

        [TestMethod]
        public void CreateSchemaTest()
        {
            ISession session = SqlUtHelper.Instance.OpenSession();
        }
    }
}